package randomwalk;

import java.util.ArrayList;
import java.util.HashMap;

import musictrackrecommendation.DatabaseDataset;
import musictrackrecommendation.ExperimentParameters;

public class QuizSetVerification {

	private ArrayList<Integer> quizUserTracks;
	private ArrayList<Integer> trainUserTracks;
	
	public QuizSetVerification(int userId) {
		ExperimentParameters parameters = ExperimentParameters.getInstance();
		DatabaseDataset dataset = parameters.getDatasetDatabase();
		quizUserTracks = dataset.getQuizUserTracks(userId);
		trainUserTracks = dataset.getTrainUserTracks(userId);
	}
	
	public boolean isRelevant(int trackId) {
		return quizUserTracks.contains(trackId);
	}

	public ArrayList<Integer> prepareTopTracks(double[] tracksPreferences,
			int trackLimit) {
		
		ArrayList<Integer> topTracks = new ArrayList<Integer>();
		
		//exclude user tracks
		for(int trackId : trainUserTracks){
			tracksPreferences[trackId] = 0.0;
		}
		
		//select preferable tracks
		HashMap<Double, Integer> tracks= new HashMap<Double, Integer>();
		for (int i = 0; i < tracksPreferences.length; i++) {
			tracks.put(tracksPreferences[i], i);
		}
		java.util.Arrays.sort(tracksPreferences);
		
		int i = 0;
		while(tracksPreferences[tracksPreferences.length - i - 1] != 0.0 && i < trackLimit) {
			topTracks.add(tracks.get(tracksPreferences[tracksPreferences.length - i - 1]));
			i++;
		}
		
		return topTracks;
		
	}

	public int relevantItemsCount() {
		return quizUserTracks.size();
	}

}
